<%@ taglib uri="/WEB-INF/bpmapp.tld" prefix="ssp" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<script language="javascript" src="<%= request.getContextPath() %>/cs/js/stringFunc.js" type="text/javascript">
</script>
<script language="JavaScript">
  function renameBookmark(csId, oldName) {
    var newName = prompt("<bean:message bundle="appCommonRes" key="cs.bookmark.rename.prompt" />", oldName);
    if (newName == null || newName == oldName) return false;
    
    if (stringTrim(newName).length == 0) {
      alert("<bean:message bundle="appCommonRes" key="cs.bookmark.rename.empty" />");
      return false;
    }
    
    //the user types in a non-empty name which is different with old name.
    var theForm = document.csBookmarkListForm;
    theForm.renamedCsId.value = csId;
    theForm.newCsName.value = newName;
    theForm.submit();
    return false;
  }
  
  function updateImportant(theForm) {
    theForm.action = "<html:rewrite page="/csBookmarkChangeListOrder.do" />";
    theForm.submit();
    return false;
  }
  
  function updateCheckbox(buttonFld, checkboxFld) {
    if (checkboxFld == null || buttonFld == null) return;
    var selectAllTxt = "<bean:message bundle="appCommonRes" key="button.selectAll" />";
    var unselectAllTxt = "<bean:message bundle="appCommonRes" key="button.unselectAll" />";
    var toBeChecked;
    if (buttonFld.value == selectAllTxt) {
      //Current buttonFld has value "select all", this means the user wants to select all checkbox.
      toBeChecked = true;
      //And we want to switch button value from "Select all" --> "Unselect all"
      buttonFld.value = unselectAllTxt;
    } else {
      //Current buttonFld has value "unselect all", this means the user wants to unselect all checkbox.
      toBeChecked = false;
      //And we want to switch button value from "Unselect all" --> "Select all"
      buttonFld.value = selectAllTxt;
    }
    if (!checkboxFld.length) {
      //The checkbox group has only one checkbox.
      checkboxFld.checked = toBeChecked;
    } else {
      for (var i = 0; i < checkboxFld.length; i ++) {
        checkboxFld[i].checked = toBeChecked;
      }
    }
  }

  
</script>

<html:form action="/csBookmarkRename.do">
  <logic:iterate id="one" name="csBookmarkListForm" property="persistedImportantCsId">
    <input type=hidden name="persistedImportantCsId" value="<bean:write name="one" />" >
  </logic:iterate>
  <input type="hidden" name="setImportantCsId" value="false">
  <input type="hidden" name="renamedCsId">
  <input type="hidden" name="newCsName">
  <table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
  <td valign="top" width="100%">
    
  <div class="app_pageTitle"><bean:message bundle="appCommonRes" key="cs.bookmark.list.pageTitle" /></div> 
  
  <div class="app_pageSubtitle">
    <span class="left"><bean:message bundle="appCommonRes" key="cs.bookmark.list.tableTilte" /></span>
    <span class="right">&nbsp;</span>
  </div> 
  <!--end page title area here-->
  
  <div class="blockWrap">
  <div class="globalButtonWrap">
    <input type="button" name="selectFlagBtn" onclick="updateCheckbox(this, this.form.importantCsId)" class="globalButton" value="<bean:message bundle="appCommonRes" key="button.selectAll" />">
    <input type="button" name="updateImportantBtn" onclick="updateImportant(this.form)" class="globalButton" value="<bean:message bundle="appCommonRes" key="button.updateImportant" />">
  </div>
  
  <!-- Start List here -->
  <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Alert List" width="100%">
    <tr class="listHeader"> 
      <th align="center"><bean:message bundle="appCommonRes" key="cs.listOrder" /></th>
      <th align="left"><bean:message bundle="appCommonRes" key="cs.bookmark.name" /></th>
      <th align="left"><bean:message bundle="appCommonRes" key="cs.status" /></th>
      <th align="left"><bean:message bundle="appCommonRes" key="cs.create.date" /></th>
      <th align="left"><bean:message bundle="appCommonRes" key="cs.complete.date" /></th>
      <th align="left"><bean:message bundle="appCommonRes" key="cs.actions" /></th>
    </tr>

    <bean:size id="csBookmarkListSize" name="csBookmarkList" />
  
    <logic:equal name="csBookmarkListSize" value="0">
      <tr class="listEven">
        <td colspan="6">
          <bean:message bundle="appCommonRes" key="cs.bookmark.no" />      
        </td>
      </tr>  
    </logic:equal>
    
    <logic:iterate id="oneItem" name="csBookmarkList" indexId="index">
      <tr class="<%=index.intValue() % 2 == 0 ? "listEven" : "listOdd"%>">
        <td align="center">
          <html:multibox property="importantCsId">
            <bean:write name="oneItem" property="micrositeId" />
          </html:multibox>
        </td>
        <td>
          <html:link page="/cs/micrositeHome.do" paramId="micrositeId" 
                 paramName="oneItem" paramProperty="micrositeId">
            <bean:write name="oneItem" property = "bookmarkName"  />
          </html:link>
        </td>
        <td>
          <logic:empty name="oneItem" property="csCloseTime">
            <bean:message bundle="appCommonRes" key="cs.status.active" />
          </logic:empty>
          <logic:notEmpty name="oneItem" property="csCloseTime">
            <bean:message bundle="appCommonRes" key="cs.status.completed" />
          </logic:notEmpty>
        </td>
        <td>
          <bean:write bundle="appCommonRes" name="oneItem" property ="creationTime" formatKey="format.datetime.short"/>
        </td>
        <td>
          <bean:write bundle="appCommonRes" name="oneItem" property ="csCloseTime" formatKey="format.datetime.short"/>
        </td>
        <td nowrap align="left">
          <a href="#" onclick="return renameBookmark(<bean:write name="oneItem" property="micrositeId" />, '<bean:write name="oneItem" property="bookmarkName"  />')"><html:img bundle="appCommonRes" page="/ca/images/action/icon_edit.gif" styleClass="actionIcon" altKey="button.rename" border="0"/></a>
        </td>
      </tr>
    </logic:iterate>
  </table>
  </div> 
  </td>
  </tr>
</table>
</html:form>


